/* BasicAction.h
 * 
 *  Author          : Alexander J. Yee
 *  Date Created    : 08/27/2014
 *  Last Modified   : 02/19/2017
 * 
 *  This is a basic framework for fork-join parallelism.
 * 
 *      BasicAction is an action that takes an optional index parameter.
 *      BasicParallelizer is a interface for a parallelism framework.
 * 
 *  Be careful when running tasks that block on I/O or network. Some frameworks
 *  have a limited number of threads. So any threads that block will be wasted
 *  CPU time.
 * 
 *  Implementations of the BasicParallelizer interface are not allowed to
 *  deadlock unless there actually is a deadlock between the tasks. In other
 *  words, forward progress must always be made provided that at least one task
 *  is able to run.
 * 
 */

#pragma once
#ifndef ymp_Concurrency_BasicAction_H
#define ymp_Concurrency_BasicAction_H
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//  Dependencies
#include "PublicLibs/Types.h"
namespace std{
    //  This is technically undefined behavior. But this is not a great place to
    //  pull in a large header like <functional>.
    template <class> class function;
}
namespace ymp{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
class BasicAction{
public:
    BasicAction(const BasicAction&) = delete;
    void operator=(const BasicAction&) = delete;

    BasicAction() = default;
    virtual ~BasicAction() = default;

public:
    virtual void run(upL_t index = 0) = 0;
};
////////////////////////////////////////////////////////////////////////////////
class BasicActionNonThrowing : public BasicAction{
public:
    virtual void run(upL_t index = 0) noexcept override = 0;
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
}
#endif
